<select name="province_id" id="province_id" class="select2" style="width:150px;">
    <option value="0">选择省</option>
</select>
<select name="city_id" id="city_id" class="select2" style="width:150px;">
    <option value="0">选择市</option>
</select>
<select name="area_id" id="area_id" class="select2" style="width:150px;">
    <option value="0">选择区</option>
</select>
<script>
    // var def_province_id = "{:input('province_id')}";
    var def_province_id = "<?php if(isset($info['province_id'])){echo $info['province_id'];}else{echo input('province_id');};?>";
    // var def_city_id = "{:input('city_id')}";
    var def_city_id = "<?php if(isset($info['city_id'])){echo $info['city_id'];}else{echo input('city_id');};?>";
    // var def_area_id = "{:input('area_id')}";
    var def_area_id = "<?php if(isset($info['area_id'])){echo $info['area_id'];}else{echo input('area_id');};?>";

    $(function(){
        set_province(0, def_province_id);
        if(def_city_id){
            set_city(def_city_id);
        }
        if(def_area_id){
            set_area(def_area_id);
        }
    });

    $('#province_id').change(function(){
        if($(this).val() == 0){
            $('#city_id').html('<option value="0">选择市</option>');
            $('#area_id').html('<option value="0">选择区</option>');
        }else{
            set_city(def_city_id);
            $('#area_id').html('<option value="0">选择区</option>');
        }
    });

    $('#city_id').change(function(){
        if($(this).val() == 0){
            $('#area_id').html('<option value="0">选择区</option>');
        }else{
            set_area(def_area_id);
        }
    });

    /**
     * 设置省选项
     */
    function set_province(pid, def_id){
        var option = '<option value="0">选择省</option>';
        option += addr_req(pid, def_id);
        $('#province_id').html(option);
    }

    /**
     * 设置市选项
     */
    function set_city(def_id){
        var option = '<option value="0">选择市</option>';
        option += addr_req($('#province_id').val(), def_id);
        $('#city_id').html(option);
    }

    /**
     * 设置区选项
     */
    function set_area(def_id){
        var option = '<option value="0">选择区</option>';
        option += addr_req($('#city_id').val(), def_id);
        $('#area_id').html(option);
    }

    /**
     * 获取省市区
     * @param pid 父id
     * @param def_id 默认选中id
     */
    function addr_req(pid, def_id){
        var return_html = '';
        $.ajax({
            async:false,
            type:'post',
            url:"{:url('index/get_addr')}",
            data:{pid:pid, def_id:def_id},
            success:function(data){
                return_html = data;
            }
        });
        return return_html;
    }
</script>